import MySQL


def createOriginDataset():
    tables = [ 'region', 'nation', 'part', 'customer', 'orders', 'supplier', 'partsupp', 'lineitem']
    for table in tables:
        sql = 'INSERT INTO tpch_1G.' + table + ' SELECT * FROM tpch.' + table
        MySQL.execute(sql)


def createIncrementalDataset():
    for i in range(225, 510, 50):
        sql = 'CREATE TABLE lineitem_inc_' + str(i) + 'w SELECT * FROM lineitem ORDER BY L_RECEIPTDATE ASC, L_ORDERKEY ASC, L_LINENUMBER ASC LIMIT ' + str(i * 10000)
        MySQL.execute(sql)


def createUpdateDataset():
    for i in range(200, 510, 50):
        sql = 'CREATE TABLE lineitem_update_' + str(i) + 'w LIKE lineitem'
        MySQL.execute(sql)
    for i in range(200, 510, 50):
        sql = 'INSERT INTO lineitem_update_' + str(i) + 'w SELECT * FROM lineitem_data_' + str(i) + 'w ORDER BY L_ORDERKEY, L_LINENUMBER DESC LIMIT 2000000'
        MySQL.execute(sql)


def createLostDataset():
    for i in range(200, 360, 50):
        sql = 'CREATE TABLE lineitem_lost_' + str(i) + 'w LIKE lineitem'
        MySQL.execute(sql)
    for i in range(200, 360, 50):
        rows = (400 - i) * 10000
        sql = 'INSERT INTO lineitem_lost_' + str(i) + 'w SELECT * FROM lineitem_data_' + str(i) + 'w ORDER BY L_ORDERKEY, L_LINENUMBER DESC LIMIT ' + str(rows)
        MySQL.execute(sql)


def createSample():
    sql = 'CREATE TABLE lineitem_inc_200w SELECT * FROM lineitem ORDER BY L_RECEIPTDATE ASC, L_ORDERKEY ASC, L_LINENUMBER ASC LIMIT 2000000'
    MySQL.execute(sql)
    for i in range(100):
        sql = 'CREATE TABLE lineitem_sample_' + '%02d' % i + ' SELECT * FROM lineitem_inc_200w ORDER BY RAND() LIMIT 10000'
        MySQL.execute(sql)

if __name__ == '__main__':
    # createOriginDataset()
    # createSample()
    createIncrementalDataset()